import {list,broadcastList,carousel} from '../../server/api'
import {openMap} from '../../server/pulbmethod'
import {removeImageTags} from '../../server/shake'
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    screenHeight:wx.getMenuButtonBoundingClientRect().top,//顶部到胶囊的高度
    jnheight:wx.getMenuButtonBoundingClientRect().height,//胶囊的的高度
    modelwidth:wx.getSystemInfoSync().windowWidth,
    modelheight:wx.getSystemInfoSync().windowHeight ,
    textcontent:'',
    datalist:[],//接收喇叭数据
    contetdata:[],
    show:false,
    pageNo:1,
    pageSize:10,
    heights:'',
    shownotice:true,
    msg: [],

    adList:[{
      'url':'',
      'title':'刚刚预约了服务'
    },{
      'url':'',
      'title':'内容内容内容内容内容'
    }],

  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
 
    this.setData({msg:[]})
    this.getmsg();
    let  menu = wx.getMenuButtonBoundingClientRect() 
    this.setData({heights:menu.top})
    this.getTabBar().toggleMenu(0)
    this.getTabBar().init()
    this.setData({
      pageNo:1,
      pageSize:10,
      contetdata:[],
    })
    wx.pageScrollTo({scrollTop: 100})
    this.getlist()
   
  },
    //获取通知信息
    async getmsg() {
      const res = await carousel();
      if (res.code == 200) {
        this.setData({msg:res.result})
      }
    },
  //获取列表数据
  async getlist(res)
  {
    const params = {
      pageNo:res == undefined ? this.data.pageNo : res.pageNo,
      pageSize:res == undefined ? this.data.pageSize : res.pageSize
    }
    const  data = await list(params)
    if(data.code == 200)
    {
      const source = data.result.records.map((item)=>{
         item.remark = removeImageTags(item.remark).length > 30  ? removeImageTags(item.remark).slice(0,30) + '.....' : removeImageTags(item.remark)
         return item
      })
      this.setData({contetdata:[...this.data.contetdata, ...source]})
    }
 
  },
  detail(e){
    const ygid = e.currentTarget.dataset.meg.id
    wx.navigateTo({
      url: `/subPackagesA/pages/werlfardetail/werlfardetail?id=${ygid}`,
    })
  },
   //打开地图
   openadd(e){
    const obj = e.currentTarget.dataset.meg
    console.log(obj,'obj');
    openMap(obj)
  },
  getMore(e){
    console.log(e,'e');
      this.data.pageNo++
      let params = {
        pageNo: this.data.pageNo,
        pageSize: this.data.pageSize
      }
    setTimeout(() => {
      if(this.data.contetdata.length - 1)
      {
        this.getlist(params)
        this.setData({show:true})
      }
    }, 1000);
   
  },
  //双箭头跳转
  gydetail(){
    wx.navigateTo({
      url: '/subPackagesA/pages/werlfarr/werlfarr',
    })
  },
  //打开地图
  openadd(e){
    const obj = e.currentTarget.dataset.meg
    openMap(obj)
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    this.setData({show:false})
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},
  //小喇叭详细信息
  // detailmsg() {
  //   wx.navigateTo({
  //     url: `/subPackagesA/pages/megdetail/megdetail`,
  //   });
  // },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom(e) {
    console.log(e,'////');
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
